using System;

namespace Petra.Gis.DataServices.SHP
{
	/// <summary>
	/// Class for holding the information assicated with a dbase field.
	/// </summary>
	public class DbaseField
	{

        
		// Field Type (C N L D or M)
    protected char _type;
        






		public static char GetDbaseType(Type type)
		{
			DbaseField dbaseColumn = new DbaseField();
			if (type == typeof(string))
				return 'C';
			else if (type == typeof(double)) { }
			else if (type == typeof(float)) { }
			else if (type == typeof(bool))
				return 'L';
			else if (type == typeof(DateTime))
				return 'D';
			throw new NotSupportedException(String.Format("{0} does not have a corresponding dbase type.", type.Name));
		}





    //public static DbaseField ShapeField()
    //{
    //  DbaseField shpfield = new DbaseField();
    //  shpfield.Name="Geometry";
    //  shpfield._type='B';
    //  return shpfield;
    //}





		public static DbaseField IdField()
		{
			DbaseField shpfield = new DbaseField();
			shpfield.Name="Row";
			shpfield._type='I';
			return shpfield;
		}




    // Field Name
    protected string _name;


    /// <summary>
    /// Field Name.
    /// </summary>
		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}
        		




    /// <summary>
    /// Field Type (C N L D or M).
    /// </summary>
		public char DbaseTypeId
		{
			get
			{

        throw new NotImplementedException();
        //Type type;
        //switch (_type)
        //{
        //  case 'L': // logical data type, one character (T,t,F,f,Y,y,N,n)
        //    type = typeof(bool);
        //    break;
        //  case 'C': // char or string
        //    type = typeof(string);
        //    break;
        //  case 'D': // date
        //    type = typeof(DateTime);
        //    break;
        //  case 'N': // numeric
        //    type = typeof(double);
        //    break;
        //  case 'F': // double
        //    type = typeof(float);
        //    break;
        //  case 'B': // BLOB - not a dbase but this will hold the WKB for a geometry object.
        //    type = typeof(byte[]);
        //    break;
        //  default:
        //    throw new NotSupportedException("Do not know how to parse Field type " + _type);
        //}
        //return type;
			}
			set
			{
				_type = value;
			}
		}





    // Field Data Address offset from the start of the record.
    protected int _dataAddress;


    /// <summary>
    /// Field Data Address offset from the start of the record.
    /// </summary>
		public int Address
		{
			get
			{
				return _dataAddress;
			}
			set
			{
				_dataAddress = value;
			}
		}






    // Length of the data in bytes
    protected int _length;


    /// <summary>
    /// Length of the data in bytes.
    /// </summary>
		public int Length
		{
			get
			{
				return _length;
			}
			set
			{
				_length = value;
			}
		}





    // Field decimal count in Binary, indicating where the decimal is
    protected int _decimalCount;

        
    /// <summary>
    /// Field decimal count in Binary, indicating where the decimal is.
    /// </summary>
    public int Decimals
		{
			get
			{
				return _decimalCount;
			}
			set
			{
				_decimalCount = value;
			}
		}





    protected System.Type _dataType;


		/// <summary>
		/// Returns the equivalent CLR type for this field.
		/// </summary>
    public Type DataType
		{
			get
			{
        return _dataType;
			}

      set { _dataType = value; }
		}



	}
}
